<template>
  <z-modal
    :width="800"
    v-bind="modalOption"
    :okText="false"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="disableSubmit">
      <a-form-model slot="detail" layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="form" :rules="validatorRules">
        <a-form-model-item label="费用编号" prop="costNo">
          <a-input placeholder="请输入费用编号" v-model.trim="form.costNo" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="费用名称" prop="costName">
          <a-input placeholder="请输入费用名称" v-model.trim="form.costName" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="项目" prop="productName">
          <a-input-search v-model="form.productName" readOnly @search="onSearchProduct" placeholder="">
          			  <a-button slot="enterButton">选择项目</a-button>
          </a-input-search>
        </a-form-model-item>
        <a-form-model-item label="客户" prop="customerName">
          <a-input-search v-model="form.customerName" readOnly @search="onSearchCustomer" placeholder="请选择客户">
        	  <a-button slot="enterButton">选择客户</a-button>
          </a-input-search>
        </a-form-model-item>
        <a-form-model-item label="项目金额" prop="amount">
          <a-input-number :min="0" placeholder="请输入金额" v-model.trim="form.amount" style="width: 100%" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="商机归属人" prop="ownerUserId">
          <ZSelectUserByDep :multi="false" v-model="form.ownerUserId" placeholder="请选择商机归属人" />
        </a-form-model-item>
        <a-form-model-item label="费用情况描述" prop="description">
          <a-textarea placeholder="请输入费用情况描述" v-model.trim="form.description" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="费用类型" prop="costType">
          <z-dict-select-tag v-model="form.categoryId" dictCode="cost_type" placeholder="请选择费用类型" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="状态" prop="status">
          <z-dict-select-tag v-model="form.status" dictCode="cost_status" placeholder="请选择状态" :disabled="disableSubmit"/>
        </a-form-model-item>
      </a-form-model>
    </j-form-container>
    </a-spin>
	<SelectCustomerModal ref="selectModal" @ok="selectOK"></SelectCustomerModal>
	<SelectProductModal ref="selectModal2" @ok="selectOK2"></SelectProductModal>
  </z-modal>
</template>

<script>
import ModalFormMixin from '@/mixins/ModalFormMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import ZSelectUserByDep from '@/components/zzbiz/ZSelectUserByDep'
import SelectCustomerModal from '@/pages/crm/customer/modules/SelectCustomerModal'
import SelectProductModal from '@/pages/crm/product/modules/SelectProductModal'
import JFormContainer from '@/components/form/JFormContainer'

export default {
  name: "crmCostModal",
  mixins: [ModalFormMixin],
  components: {
    JFormContainer,
    ZDictSelectTag,
    ZSelectUserByDep,
	SelectCustomerModal,
	SelectProductModal
  },
  data() {
    return {
      validatorRules: {
        costName: [
          { required: true, message: '请输入费用名称!' }
        ],
        costNo: [
          { required: true, message: '请输入费用编号!' }
        ],
      },
      url: {
        add: '/cost/add',
        edit: '/cost/edit',
        queryById: "/cost/queryById"
      },
      // 查询参数
      queryParam: {},
      selectedRowKeys: [],
      selectedRows: [],
      toggleSearchStatus: false
    }
  },
  methods: {
    addAfter() {
    },
	onSearchCustomer() {
	  this.$refs.selectModal.showModal()
	},
	onSearchProduct() {
	  this.$refs.selectModal2.showModal()
	},
	selectOK(rows, idstr) {
	  if(!rows){
	    this.form.customerId = ''
	    this.form.customerName = ''
	  }else{
	    let row = rows[0]
	    this.form.customerId = row.id
	    this.form.customerName = row.customerName
	  }
	  this.form = Object.assign({},this.form)
	},
	selectOK2(rows, idstr) {
	  if(!rows){
	    this.form.productId = ''
	    this.form.productName = ''
	  }else{
	    let row = rows[0]
	    this.form.productId = row.id
	    this.form.productName = row.name
	  }
	  this.form = Object.assign({},this.form)
	}
  }
}
</script>
